package com.zgjkhis.modules.system.service.mapper;

import com.zgjkhis.common.mapper.CoreMapper;
import com.zgjkhis.modules.system.domain.DrugDelivery;
import com.zgjkhis.modules.system.service.dto.DrugDeliveryQueryCriteria;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author yzq
 * @Description 药品入库
 * @Date 2021/6/23 9:48
 * @Param
 * @return
 **/
@Repository
public interface DrugDeliveryMapper extends CoreMapper<DrugDelivery> {


    @Select("<script>select * from his_drug_delivery t \n" +
            "where 1=1 and t.pharmacy_id=#{drugDelivery.pharmacyId}\n" +
            "<if test=\"drugDelivery.status !=null and drugDelivery.status!=''\">\n" +
            "and t.status=#{drugDelivery.status}\n" +
            "</if>\n" +
            "<if test=\"drugDelivery.deliveryType !=null and drugDelivery.deliveryType!=''\">\n" +
            "and t.delivery_type=#{drugDelivery.deliveryType}\n" +
            "</if>\n" +
            "<if test=\"drugDelivery.drugType !=null and drugDelivery.drugType!=''\">\n" +
            "and t.drug_type=#{drugDelivery.drugType}\n" +
            "</if>\n" +
            "<if test=\"drugDelivery.startTime !=null \">\n" +
            " and t.create_time  &gt; #{drugDelivery.startTime}\n" +
            "</if>\n" +
            "<if test=\"drugDelivery.endTime !=null \">\n" +
            " and t.create_time  &lt; str_to_date(DATE_ADD(#{drugDelivery.endTime},INTERVAL 1 DAY), '%Y-%m-%d %H')\n" +
            "</if>\n" +
            "<if test=\"drugDelivery.deliveryNo !=null and drugDelivery.deliveryNo!=''\">\n" +
            "and t.delivery_no=#{drugDelivery.deliveryNo}\n" +
            "</if></script>")
    List<DrugDelivery> findAllByPageable(@Param("drugDelivery") DrugDeliveryQueryCriteria criteria);
}
